/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.una.accidentmanagement.view.manipulator;

import br.com.una.accidentmanagement.bo.TicketController;
import br.com.una.accidentmanagement.model.ActionTicket;
import br.com.una.accidentmanagement.model.Requester;
import br.com.una.accidentmanagement.model.Ticket;
import br.com.una.accidentmanagement.model.TicketFile;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author santosmgbh
 */
public class FilesTable extends DefaultTableModel{
    
    private List<TicketFile> files = new LinkedList<TicketFile>();                     
    public FilesTable() {
        createColumns();    
    }
    
    

    public List<TicketFile> getFiles() {
        return files;
    }
    
    

    public FilesTable(List<TicketFile> files) {        
        this.files = files;
        createColumns();        
    }       
    
    public void putFile(TicketFile ticketFile){
        files.add(ticketFile);
        refresh();
    }
    
    public void refresh(){                
        cleanDate();
        pushDate();
    }

    @Override
    public boolean isCellEditable(int row, int column) {
        return false; //To change body of generated methods, choose Tools | Templates.
    }
    
    public void delete(int index){
        files.remove(index);
        refresh();
    }
    
    
    private void cleanDate(){
        int size = getRowCount();
        for(int i = 0; i < size; i++){
            removeRow(0);
        }
    }
    
    private void createColumns(){
        addColumn("Código");
        addColumn("Nome");
        addColumn("Data");        
    }        
    
    private void pushDate(){    
        int pos = 0;
        for(TicketFile t: files){                        
            addRow(new RowTicket((pos++)+"", t.getName(), t.getAddedDate().toString()));
        }        
    }        
    
    class RowTicket extends Vector{        
        RowTicket(String codigo, String fileName, String dateAdded) {
            add(codigo);
            add(fileName);
            add(dateAdded);            
        }
        
        
        
    }
    
    
}
